import com.troyworks.particleengine.Particle;
/**
 * @author Troy Gardner
 */
class com.troyworks.particleengine.Ch15_09 extends MovieClip {
	var p : Particle;
	var tp : Particle;
	var easing : Number = .1;
	var fl : Number = 250;
	var vpX : Number = _width/2;
	var vpY : Number = _height/2;
	var ball : MovieClip;
	
	public function Ch15_09() {
		
	}
	public function onLoad() : Void{

		vpX  = _width/2;
		vpY  = _height/2;

		p  = new Particle();
		tp  = new Particle();
		tp.x = Math.random()*_width-_width/2;
		tp.y = Math.random()*_height-_height/2;
	}
	function onEnterFrame() : Void {
		trace("onEnterFrame()");
		var dx : Number = tp.x-p.x;
		var dy : Number = tp.y-p.y;
		var dz : Number = tp.z-p.z;
		p.x += dx*easing;
		p.y += dy*easing;
		p.z += dz*easing;
		var dist : Number = Math.sqrt(dx*dx+dy*dy+dz*dz);
		if (dist<1) {
				tp.x = Math.random()*_width-_width/2;
				tp.y = Math.random()*_height-_height/2;
				tp.z = Math.random()*_width-_width/2;
		}
		if (p.z <=-fl) {
				ball._visible = false;
		} else {
				ball._visible = true;
				var scale : Number = fl/(fl+p.z);
				ball._xscale = ball._yscale=scale*100;
				ball._x = vpX+p.x*scale;
				ball._y = vpY+p.y*scale;
		}
	}
	
}